package cate.game.activity.converthero.msg;

import cate.common.annotation.OperationSetter;
import cate.common.table.d.GDOperation;
import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.activity.converthero.ConvertHeroActivity;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBConvertHero;
import easy.java.dev.note.NoteField;

import java.util.Set;

@ClientMsg(title = "兑换英雄 的 请求")
@OperationSetter(value = GDOperation.CONVERT_HERO)
public class ConvertHeroReq implements MsgInput {
    @NoteField("功能id")
    public int funcId;
    @NoteField("配置id")
    public int tid;
    @NoteField("英雄id")
    public Set<String> uids;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        ConvertHeroActivity hero = cc.getRole().getActivity().getEnableActivitySingle(funcId);
        if (hero == null) {
            cc.getRole().getGame().notice.message(cc.getRole(), "活动未开启");
            return;
        }
        GameResult<ConvertHeroActivity> r = hero.convert(tid, uids);
        if (!r.ok()) {
            game.notice.message(cc.getRole(), r.message);
        } else {
            r.data.noticeUpdate();
        }
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBConvertHero.CONVERT_HERO_REQ;
    }
}
